<style>
    #auto {
        color: #fff;
        background-color: #3bb4f2;
        border-color: #3bb4f2;
    }

    .unuse {
        background-color: #9ca5af !important;
        border-color: #9ca5af !important;
    }

    .red {
        color: red
    }

    .gexing {
        display: none
    }

    .gexing .am-checkbox-inline {
        float: left;
    }

    .fbneirong .zuo {
        margin-bottom: 5px;
    }

    .fbneirong .you {
        margin-bottom: 5px;
    }

</style>


<div class="admin-biaogelist">

    <div class="listbiaoti am-cf">
        <ul class="am-icon-flag on"> <?php echo $this->address; ?>    </ul>

        <ul style="margin-left: 200px;">任务池剩余单量：<?php echo $this->poolnub2; ?></ul>

        <dl class="am-icon-home" style="float: right;">当前位置： 首页 > <a href="#">拼多多接单</a></dl>

        <!--<dl>
          <button type="button" class="am-btn am-btn-danger am-round am-btn-xs am-icon-plus" > 补充线订单</button>
        </dl>-->
        <!--这里打开的是新页面-->

    </div>

    <div class="fbneirong" style="padding-top: 0px">


        <form class="am-form jdtask">


            <div class="picurl" style=" display: none; position: absolute;  left: 800px;  top: 150px;">
                <div style="text-align: center;color: #0a9ffe;font-weight: 700">主图</div>
                <img src="" width="350px;" height="250px;">
            </div>
            <!--      <div class="showpic" style="display: none; position: absolute;  left: 1170px;  top: 150px;">
                      <div style="text-align: center;color: #0a9ffe;font-weight: 700">晒图</div>
                      <img src="" width="350px;" height="350px;">
                  </div>-->

            <div class="showtext" style="display: none; position: absolute;  left: 1170px;  top: 150px;">
                <div style="text-align: center;color: #0a9ffe;font-weight: 700">指定评论</div>
                <span class="text" style="color: red;font-size: 18px"></span>
            </div>

            <div class="am-form-group am-cf">

                <input type="hidden" name="id" value="">
                <div id="Pagination" style="margin:20px auto" style="display:none"></div>
                <div class="zuo">获取任务数量：</div>
                <div class="zuo" style="width: 300px;">
                    <input type="number" class="am-input-sm" name="epage" placeholder="获取数量（1-5）">
                </div>
                <div id="updata" class="am-btn am-btn-secondary am-radius" style="float: left">获取任务</div>
                <div class="zuo">指定店铺：</div>
                <div class="zuo" style="width: 300px;">
                    <input type="text" class="am-input-sm" id="shopname" placeholder="输入店铺名">
                </div>
                <!--     <div    id="auto" class="am-btn  am-radius unuse">自动获取</div>-->
            </div>

            <div class="am-form-group am-cf">
                <div class="zuo">标题：</div>
                <div class="you">
                    <input type="text" name="goods_name" class="am-input-sm" style="width: 500px" id="doc-ipt-email-1"
                           disabled placeholder="请输入标题">
                </div>
            </div>

            <div class="am-form-group am-cf">
                <div class="zuo">店铺名：</div>
                <div class="you">
                    <input type="text" name="shop_name" class="am-input-sm" style="width: 500px" id="doc-ipt-email-1"
                           disabled placeholder="请获取店铺名">
                </div>
            </div>
            <div class="am-form-group am-cf">
                <div class="zuo">实际价格：</div>
                <div class="zuo">
                    <input type="text" name="price" class="am-input-sm" style="width: 200px" id="doc-ipt-email-1"
                           disabled placeholder="请输入价格">
                </div>
            </div>

            <div class="am-form-group am-cf">
                <div class="zuo">商品链接：</div>
                <div class="you">
                    <input type="text" name="link" class="am-input-sm" id="doc-ipt-email-1"
                           style="width: 320px;float: left"
                           placeholder="请输入商品链接">
                    <div style="margin-left: 0px;" class="fangwen  am-btn am-btn-secondary am-radius"><a href=""
                                                                                                         target="_Blank">访问</a>
                    </div>
                    <div style="margin-left: 0px;" class="pifa am-btn am-btn-secondary am-radius"><a href=""
                                                                                                     target="_Blank">批发</a>
                    </div>
                </div>

            </div>

            <div class="am-form-group am-cf">
                <div class="zuo">订单类型：</div>
                <div class="you" style="margin-top: 4px;">
                    <label class="am-radio-inline">
                        <input type="radio" value="1" name="type_h"> 普通单
                    </label>
                    <label class="am-radio-inline">
                        <input type="radio" value="2" name="type_h"> 高留评单
                    </label>
                    <label class="am-radio-inline">
                        <input type="radio" value="3" name="type_h"> 多多进宝
                    </label>
                    <label class="am-radio-inline">
                        <input type="radio" value="4" name="type_h"> 拼多多直播间
                    </label>

                </div>
            </div>


            <div class="am-form-group am-cf">

                <div class="zuo">购买件数：</div>
                <div class="zuo">
                    <input type="text" name="number" class="am-input-sm" id="doc-ipt-email-1" disabled
                           style="color: red; font-size: 18px;" placeholder="请输入件数">
                </div>


                <!--  <div class="zuo">购买SKU：</div>
                  <div class="zuo">
                      <input type="text"   name="sku" class="am-input-sm" id="doc-ipt-email-1"  disabled  placeholder="请输入SKU">
                  </div>-->


            </div>


            <div class="am-form-group am-cf">
                <div class="zuo">购买类型选择：</div>
                <div class="you" style="margin-top: 4px;">
                    <label class="am-radio-inline">
                        <input type="radio" value="1" name="pay_type"> 全部开团
                    </label>
                    <label class="am-radio-inline">
                        <input type="radio" value="2" name="pay_type"> 单独购买
                    </label>
                    <label class="am-radio-inline">
                        <input type="radio" value="3" name="pay_type"> 优先参团
                    </label>
                    <!-- <div class="zuo">SKU：</div>
                     <div class="zuo">
                         <input type="text"   name="sku" class="am-input-sm" id="doc-ipt-email-1" placeholder="请输入SKU">
                     </div>-->

                </div>
            </div>

            <div class="am-form-group am-cf gexing">
                <div class="zuo">账户性别：</div>
                <div class="you" style="margin-top: 4px;">
                    <label class="am-radio-inline">
                        <input type="radio" value="0" name="sex">男女随意
                    </label>
                    <label class="am-radio-inline">
                        <input type="radio" value="1" name="sex"> 男号
                    </label>
                    <label class="am-radio-inline">
                        <input type="radio" value="2" name="sex"> 女号
                    </label>

                </div>
            </div>

            <div class="am-form-group am-cf gexing">
                <div class="zuo">个性设置：</div>
                <div class="you">
                    <div class="zuo" style="width: 670px">
                        <label class="am-checkbox-inline">
                            <input type="checkbox" disabled name="chat">假聊(2金币)
                        </label>
                        <label class="am-checkbox-inline">
                            <input type="checkbox" disabled name="compare">货比三家(1金币)
                        </label>
                        <label class="am-checkbox-inline">
                            <input type="checkbox" disabled name="collection">收藏商品收藏店铺(2金币)
                        </label>
                        <label class="am-checkbox-inline">
                            <input type="checkbox" disabled name="sign">签收(1金币)
                        </label>
                        <label class="am-checkbox-inline">
                            <input type="checkbox" disabled name="overnight">隔夜收藏(2金币)
                        </label>
                        <label class="am-checkbox-inline">
                            <input type="checkbox" disabled name="dianzan">评论点赞(0.5金币)
                        </label>

                    </div>
                </div>
            </div>

            <div class="am-form-group am-cf">
                <div class="zuo">付款总额：</div>
                <div class="zuo">
                    <input type="text" name="allmoney" class="am-input-sm" id="doc-ipt-email-1"
                           style="color: red; font-size: 18px;" disabled placeholder="请输入付款总额">
                </div>
                <div class="zuo">搜索关键词：</div>
                <div class="zuo">
                    <input type="text" name="keyword" class="am-input-sm" id="doc-ipt-email-1" style="width: 700px;"
                           placeholder="请输入关键词">
                </div>
            </div>


            <div class="am-form-group am-cf">
                <div class="zuo">sku：</div>
                <div class="you">
                    <input type="text" name="sku" class="am-input-sm" id="doc-ipt-email-1" disabled placeholder="SKU">
                </div>
            </div>

            <div class="am-form-group am-cf">
                <div class="zuo">备注：</div>
                <div class="you">
                    <input type="text" name="remarks" class="am-input-sm" id="doc-ipt-email-1" disabled
                           placeholder="备注">
                </div>
            </div>

            <div class="am-form-group am-cf">
                <div class="zuo">实际付款价格：</div>
                <div class="zuo">
                    <input type="text" name="real_price" class="am-input-sm" id="doc-ipt-email-1" autocomplete="off"
                           placeholder="实际付款价格">
                </div>

                <div class="zuo">awz标识：</div>
                <div class="zuo">
                    <input type="text" name="awz" class="am-input-sm" id="doc-ipt-email-1" autocomplete="off"
                           placeholder="请输入awz">
                </div>
            </div>
            <div class="am-form-group am-cf">
                <div class="zuo">订单号：</div>
                <div class="zuo" style="width: 250px">
                    <input type="text" name="orderid" class="am-input-sm" id="doc-ipt-email-1" maxlength="22"
                           autocomplete="off" value="" placeholder="请输入商品订单号">
                </div>
                <div class="zuo addrees">收货人信息：</div>
                <div class="zuo addrees" style="width: 800px">
                    <input type="text" name="addrees" class="am-input-sm" id="doc-ipt-email-1" autocomplete="off"
                           placeholder="请输入收货人信息">
                </div>
            </div>
            <div class="am-form-group am-cf">
                <div class="you" style="margin-left: 11%;">
                    <div id="finish" style="margin-left: 50px;" class="am-btn am-btn-secondary am-radius">提交任务</div>
                    <div id="replace" style="margin-left: 200px;" class="am-btn am-btn-secondary am-radius">替换任务</div>
                    <div id="throwtask" style="margin-left: 200px;" class="am-btn am-btn-secondary am-radius">放弃任务</div>


                </div>
            </div>
        </form>


    </div>


    <script>
        var taskste = '';
        var on_request = false;
        var type = 1;
        var page = 1;
        var log = "<?php  echo $awz; ?>";
        var date = "<?php  echo date('ymd'); ?>-";
        var daifa = false;

        log = log * 1;
        var awz = "0";
        if (log > 0) {
            getjdtask(1);
            $("#updata").attr("disabled", 'true');
        }
        $("#updata").click(function () {
            getjdtask();
        });

        $("#auto").click(function () {
            if (log > 0) {
                auto = 0;
                $("#auto").addClass("unuse");
                return;
            }
            if (auto == 0) {
                auto = 1;
                $("#auto").removeClass("unuse");
                loop();
            } else {
                auto = 0;
                $("#auto").addClass("unuse");
            }

        });

        function loop() {
            if (auto != 0 && log <= 0) {
                getjdtask(2);
                setTimeout("loop()", 1000);
            }
        }


        function getjdtask(hastask) {
            if (on_request) {
                //alert("等待");
                //return;
            }
            if (hastask != 1) {
                /* var newawz =prompt("请输入您的awz标示");
                 if(newawz=='' ||newawz==null){
                     alert("awz不能为空");return;
                 }*/
            }
            var newawz = "";
            var url = "<?php echo base_url(); ?>Hunter/getpddtaskaction";
            var epage = $("input[name='epage']").val();
            let shop_name=$("#shopname").val();
            if (epage == "") {
                epage = 10;
            }
            if (epage < 6) {
                epage = 10
            }
            var postdata = {
                'awz': newawz,
                'page': page,
                'epage': epage,
                'shop_name': shop_name
            };





            awz = newawz;
            on_request = true;
            $.post(url, postdata, function (data) {
                on_request = false;
                if (data.code == 0) {
                    $("input[name='epage']").val(data.count);
                    setlisthtnml(data, page);
                    log = data.count;
                    setPagination("Pagination", data.count, page, 1, function (clickPage) {
                        page = parseInt(clickPage) + 1;
                        showtask(page);
                    });
                } else {
                    layer.msg(data.msg)
                }
            }, 'json');
        }


        /**
         * 切换显示不同任务
         * @param nub
         */
        function showtask(nub) {
            nub = nub - 1;
            var html = '';
            if (taskste.length > 0) {
                var str = taskste[nub];
                setlisthtml2(str);
                $('#Pagination').show();
            } else {
                html += '<li><div style="width:100%;text-align:center;">&nbsp暂无数据</div></li>';
                $(".impowdith").html(html);
                $('#Pagination').hide();
            }
        }

        function setlisthtnml(data, nub) {
            nub = nub - 1;
            var html = '';
            if (data.list.length > 0) {
                $.each(data.list, function (key, value) {
                    data.list[key]['allmoney'] = data.list[key]['price'] * data.list[key]['number'];
                    data.list[key]['orderid'] = date;
                    data.list[key]['real_price'] = "";
                    if (awz != "0" && awz != undefined) {
                        data.list[key]['awz'] = awz;
                    }
                });
                taskste = data.list;
                var str = data.list[0];
                setlisthtml2(str);
                $('#Pagination').show();
            } else {
                html += '<li><div style="width:100%;text-align:center;">&nbsp暂无数据</div></li>';
                $(".impowdith").html(html);
                $('#Pagination').hide();
            }

        }


        function setlisthtml2(str) {
            if (str.type_h == 2) {

                let url = 'https://pifa.pinduoduo.com/goods/detail/?gid=' + str.link;
                $(".pifa a").attr("href", url);
                $(".pifa").show();
                url = 'https://mobile.yangkeduo.com/goods.html?goods_id=' + str.link;
                $(".fangwen a").attr("href", url);

            } else {
                $(".pifa").hide();
            }

            $.each(str, function (key, value) {
                taskste['allmoney'] = taskste['price'] * taskste['number'];
                if (taskste['orderid'] == null) {
                    taskste['orderid'] = date;
                }
                if (key != 'pay_type' && key != 'type_h' && key != 'sex') {
                    let type = $("input[name='" + key + "']").attr("type");
                    if (type == "checkbox") {
                        if (value == 1) {
                            $("input[name='" + key + "']").attr("checked", 'checked');
                            $("input[name='" + key + "']").parents("label").css("color", "red")
                            $("input[name='" + key + "']").parents("label").show();
                        } else {
                            $("input[name='" + key + "']").attr("checked", false);
                            $("input[name='" + key + "']").parents("label").css("color", "black")
                            $("input[name='" + key + "']").parents("label").hide();
                        }
                    } else {
                        $("input[name='" + key + "']").val(value);
                    }

                } else {
                    if (key == "pay_type") {
                        setpaytype(value);
                    }
                    if (key == "type_h") {
                        settype_h(value);
                    }
                    if (key == "sex") {
                        setsex(value);
                    }


                }

                if (str.picurl) {
                    var picurl = str.picurl;
                    $(".picurl img").attr('src', picurl)
                    $(".picurl").show()
                } else {
                    $(".picurl").hide();
                }
                /*   if (str.showpicid != 0) {
                       var picurl = str.showpicid;
                       $(".showpic img").attr('src', picurl)
                       $(".showpic").show();

                   } else {
                       $(".showpic").hide();

                   }*/


                if (str.comment != 0) {
                    $(".showtext .text").text(str.text)
                    $(".showtext").show();
                } else {
                    $(".showtext").hide();
                }


                if (str.daifa == 1) {
                    daifa = true;
                    $(".addrees").show()
                } else {
                    daifa = false;
                    $(".addrees").hide();
                }


                if (str.type_h != 2) {
                    $(".fangwen a").attr("href", str.link);
                }


                if (key == "orderid") {
                    if (value != null && value != date) {
                        $("#finish").attr("disabled", 'true');
                        $("#finish").text("已完成");
                        $("input[name='real_price']").attr("disabled", 'true');
                        $("input[name='orderid']").attr("disabled", 'true');
                    } else {
                        $("#finish").removeAttr("disabled");
                        $("input[name='real_price']").removeAttr("disabled");
                        $("input[name='orderid']").removeAttr("disabled");
                        $("#finish").text("提交任务");
                    }
                }
            });


        }


        function setpaytype(value) {
            $.each($("input[name='pay_type']"), function (i, v) {
                $(this).parents("label").css("color", "black");
                $(this).parents("label").hide();
            })

            $('input[name="pay_type"]').get(value - 1).checked = true;
            $("input[name='pay_type']:radio[value='" + value + "']").parents("label").css("color", "red")
            $("input[name='pay_type']:radio[value='" + value + "']").parents("label").show();
        }

        function setsex(value) {
            $.each($("input[name='sex']"), function (i, v) {
                $(this).parents("label").css("color", "black");
                $(this).parents("label").hide();
            })
            $('input[name="sex"]').get(value).checked = true;
            $("input[name='sex']:radio[value='" + value + "']").parents("label").css("color", "red")
            $("input[name='sex']:radio[value='" + value + "']").parents("label").show();
        }

        function settype_h(value) {
            if (value == 1) {
                $(".gexing").show();
            } else {
                $(".gexing").hide();
            }
            $.each($("input[name='type_h']"), function (i, v) {
                $(this).parents("label").css("color", "black");
                $(this).parents("label").hide();
            })

            $('input[name="type_h"]').get(value - 1).checked = true;
            $("input[name='type_h']:radio[value='" + value + "']").parents("label").css("color", "red");
            $("input[name='type_h']:radio[value='" + value + "']").parents("label").show();
        }


        $("#finish").click(function () {
            if (on_request) {
                return;
            }
            var id = $("input[name='id']").val();
            var orderid = $("input[name='orderid']").val();
            var real_price = $("input[name='real_price']").val();
            var awz = $("input[name='awz']").val();

            var addrees = $("input[name='addrees']").val();


            if (orderid == date || orderid == "") {
                layer.msg('订单缺少');
                $("input[name='orderid']").focus();
                return;
            }
            if (orderid.length != 22) {
                layer.msg('订单不足22位');
                $("input[name='orderid']").focus();
                return;
            }
            if (awz == "") {
                layer.msg('缺少azw');
                $("input[name='awz']").focus();
                return;
            }
            if (real_price == "0.00") {
                layer.msg('缺少价格');
                $("input[name='real_price']").focus();
                return;
            }
            if (id == "" || orderid == "" || real_price == "") {
                layer.msg('缺少参数');
                return;
            }
            if (daifa && addrees == "") {
                layer.msg('缺少快递地址');
                return;
            }
            var url = "<?php echo base_url(); ?>Hunter/finnish";
            var postdata = {
                'real_price': real_price,
                'awz': awz,
                'id': id,
                'project': 2,
                'orderid': orderid,
                'addrees': addrees,
            };
            on_request = true;
            $.post(url, postdata, function (data) {
                on_request = false;
                layer.msg(data.msg);
                if (data.code == 0) {
                    if ((log * 1) - 1 == 0) {//如果记录的任务全部完成则刷新页面
                        window.location.reload();
                    } else {
                        addorderid(orderid, awz, id, real_price);
                        log = log - 1;
                        $(".pagination .next").click();
                    }

                }
            }, 'json');
        });


        function addorderid(orderid, awz, id, real_price) {
            if (taskste != "") {
                $("#finish").attr("disabled", 'true');
                $("#finish").text("已完成");
                $.each(taskste, function (key, value) {
                    $.each(value, function (key2, value2) {
                        if (key2 == "id" && value2 == id) {
                            if (taskste[key]['orderid'] == null || taskste[key]['orderid'] == date) {
                                taskste[key]['orderid'] = orderid;
                            }
                            if (taskste[key]['awz'] == null || taskste[key]['awz'] == "") {
                                taskste[key]['awz'] = awz;
                            }
                            if ((taskste[key]['real_price'] == null || taskste[key]['real_price'] == "0.00" || taskste[key]['real_price'] == '') && real_price != '0.00' && real_price != 0) {
                                taskste[key]['real_price'] = real_price;
                            }
                        }
                    });
                });
            }
        }


        $("#replace").click(function () {
            if (on_request) {
                return;
            }

            var postdata = [];
            var id = $("input[name='id']").val();
            var url = "<?php echo base_url(); ?>Hunter/repalcetask/2";
            var epage = $("input[name='epage']").val();
            var newawz = "";
            /*     var newawz =prompt("请输入您的awz标示");
                 if(newawz=='' ||newawz==null){
                     alert("awz不能为空");return;
                 }*/
            if (epage == "") {
                epage = 3;
            }
            page = 1;
            var postdata = {
                'page': page,
                'awz': newawz,
                'id': id,
                'epage': epage
            };
            on_request = true;
            $.post(url, postdata, function (data) {
                on_request = false;
                if (data.code == 0) {
                    $("input[name='epage']").val(data.count);
                    setlisthtnml(data, page);
                    log = data.count;
                    setPagination("Pagination", data.count, page, 1, function (clickPage) {
                        page = parseInt(clickPage) + 1;
                        showtask(page);
                    });
                } else {
                    layer.msg(data.msg);
                }

            }, 'json');
        });


        $("#throwtask").click(function () {
            if (on_request) {
                return;
            }
            var id = $("input[name='id']").val();
            var url = "<?php echo base_url(); ?>Hunter/throwtask/2";
            var postdata = {
                'id': id
            };
            on_request = true;
            $.post(url, postdata, function (data) {
                on_request = false;
                if (data.code == 0) {
                    window.location.reload();
                } else {
                    layer.msg(data.msg)
                }
            }, 'json');
        });


    </script>


</div>

</div>


</div>


<!--<script src="http://libs.baidu.com/jquery/1.11.1/jquery.min.js"></script>-->
<script src="http://cdn.staticfile.org/modernizr/2.8.3/modernizr.js"></script>
<script src="<?php echo base_url() . 'public/business/'; ?>assets/js/polyfill/rem.min.js"></script>
<script src="<?php echo base_url() . 'public/business/'; ?>assets/js/polyfill/respond.min.js"></script>
<script src="<?php echo base_url() . 'public/business/'; ?>assets/js/amazeui.legacy.js"></script>


<!--[if (gte IE 9)|!(IE)]><!-->
<script src="<?php echo base_url() . 'public/business/'; ?>assets/js/amazeui.min.js"></script>
<!--<![endif]-->


</body>
</html>